﻿using System;
using ProtoBuf;
using ZyGames.Framework.Common;
using ZyGames.Framework.Model;
using ZyGames.Framework.Cache.Generic;

using System.Collections.Generic;

namespace ZyGames.DZPocker.Model
{
	/// <summary>
	/// 群聊房间对象
	/// </summary>
	[Serializable, ProtoContract]
	public class TalkingTable : MemoryEntity
	{
		List<GameUser> _gameUser;
		List<int> _canEnterTableIds;
		public TalkingTable()
		{
			_gameUser = new List<GameUser>();
			_canEnterTableIds = new List<int>();
		}

		private int id;

		/// <summary>
		/// 群聊房间编号
		/// </summary>
		[ProtoMember(1)]
		public int ID
		{
			get { return id; }
			set { id = value; }
		}

		[ProtoMember(2)]
		public List<GameUser> UsersInTalkingTable
		{
			get { return _gameUser; }
			set { _gameUser = value; }
		}

		[ProtoMember(3)]
		public List<int> CanEnterTableIds
		{
			get { return _canEnterTableIds; }
			set { _canEnterTableIds = value; }
		}

		public void Clear()
		{
			id = 0;
			_gameUser.Clear();
		}

		public bool Add(GameUser user)
		{
			if (UsersInTalkingTable.Contains(user))
			{
				return false;
			}
			if (!CanEnterTableIds.Contains(user.GetUserId()))
				return false;
			UsersInTalkingTable.Add(user);
			CanEnterTableIds.Remove(user.GetUserId());
			return true;
		}

		public bool AddCanIntoTable(int userid)
		{
			if (CanEnterTableIds.Contains(userid))
				return false;
			CanEnterTableIds.Add(userid);
			return true;
		}

		public bool AddRangeIntoTable(List<int> userids)
		{
			CanEnterTableIds.AddRange(userids);
			return true;
		}

		public bool Delete(GameUser user)
		{
			return UsersInTalkingTable.Remove(user);
		}
	}
}
